<?php 
if(isset($_POST['frmloadfile'])){
	
if (((	$_FILES["file"]["type"] == "image/gif")
		|| ($_FILES["file"]["type"] == "image/jpeg")|| ($_FILES["file$i"]["type"] == "image/png")
		|| ($_FILES["file"]["type"] == "image/pjpeg"))
		&& ($_FILES["file"]["size"] < 200000000))
  {
	  $msg.="File valid <br />";
  if ($_FILES["file"]["error"] > 0)
    {
    $msg= "Return Code:  " . $_FILES["file"]["error"] . " File had errors<br />";
    }
  else
    {

    if (file_exists("images/".$_FILES["file"]["name"]))
      {
      		$msg = $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
		  $lastResource = 
    	  move_uploaded_file($_FILES["file"]["tmp_name"],"images/".$_FILES["file"]["name"]);
		  $filename = $_FILES["file"]["name"];
  	   	  $msg ="Stored in: "."images/". $_FILES["file"]["name"];
		  $img = "images/".$_FILES["file"]["name"];
		  $arraySizes = array(480,120,250,640);
		
		//	$th = createThumb($img, 50);
//			imagejpeg ($th,"images/50_".$filename);
//			
//			$th = createThumb($img, 120);
//			imagejpeg ($th,"images/120_".$filename);
//			
//			$th = createThumb($img, 250);
//			imagejpeg ($th,"images/250_".$filename);
			
		
			unlink($img);
      
    }
  }
  

}
	
}
function createThumb($sourceimg, $preferedSize){
$mainImage = imagecreatefromjpeg($sourceimg);

$mainWidth = imagesx($mainImage);
$mainHeight = imagesy ($mainImage) ;
if($mainWidth<$preferedSize || $mainHeight <$preferedSize)
{
	$thumbWidth = $mainWidth;
	$thumbHeight = $mainHeight;
}else { 
	
	$thumbHeight = intval(($mainHeight *$preferedSize) /$mainWidth);
	$thumbWidth = $preferedSize;
}
$myThumbnail = imagecreatetruecolor($thumbWidth, $thumbHeight);

imagecopyresampled($myThumbnail, $mainImage, 0, 0,0,0, $thumbWidth,$thumbHeight, $mainWidth, $mainHeight);
return  $myThumbnail;

}
echo $msg." Here ".$img;?>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<input type="file" name="file" id="file">
<input type="hidden" name="frmloadfile" id="frmloadfile">
  <input type="submit" name="button" id="button" value="Submit">
</form>
